package com.rayo.accesscontrollercopy.module.welcome;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.ProgressBar;

import com.github.ybq.android.spinkit.style.DoubleBounce;
import com.rayo.accesscontrollercopy.R;
import com.rayo.accesscontrollercopy.app.ActivityManager;
import com.rayo.accesscontrollercopy.app.BaseActivity;
import com.rayo.accesscontrollercopy.module.main.MainActivity;
import com.rayo.accesscontrollercopy.module.setting.SettingActivity;


/**
 * Created by yanghaojie on 16/7/13.
 */
public class WelcomeActivity extends BaseActivity implements IWelcomeView {
    private WelcomePresenter presenter;
    private ProgressBar spinKitView;

    @Override
    protected int getLayoutId() {

        ActivityManager.getInstance().putActivity(getClass().getSimpleName(), this);
        return R.layout.activity_welcome;
    }

    @Override
    protected void setupViews() {
        spinKitView = (ProgressBar) findViewById(R.id.pb_welcome_loading);
        DoubleBounce doubleBounce = new DoubleBounce();
        spinKitView.setIndeterminateDrawable(doubleBounce);
    }

    @Override
    protected void initialized() {
        presenter = new WelcomePresenter(this, this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityManager.getInstance().removeActivity(getClass().getSimpleName());
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void goToSetting() {
        startActivity(new Intent(this, SettingActivity.class));
        finish();
    }

    @Override
    public void goToMain() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    @Override
    public void showProgressBar(boolean isShow) {

    }

    @Override
    public void showSnackBar(String txt) {
        showShortSnackbar(spinKitView, txt, null);
    }

    @Override
    public void showAlertDialog(String txt) {
        if (null != txt)
            new AlertDialog.Builder(getContext()).setTitle(R.string.app_name).setMessage(txt)
                    .setIcon(R.mipmap.ic_launcher).setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
    }
}
